package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.ResearchDepartment;
import com.hwadee.teachingprocessmanagementsystem.dao.ResearchDepartmentDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.ResearchDepartmentService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * 教研室表(ResearchDepartment)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:03
 */
@Service("researchDepartmentService")
public class ResearchDepartmentServiceImpl implements ResearchDepartmentService {
    @Resource
    private ResearchDepartmentDao researchDepartmentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param researchDepartmentId 主键
     * @return 实例对象
     */
    @Override
    public ResearchDepartment queryById(Integer researchDepartmentId) {
        return this.researchDepartmentDao.queryById(researchDepartmentId);
    }

    /**
     * 分页查询
     *
     * @param researchDepartment 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ResearchDepartment> queryByPage(ResearchDepartment researchDepartment, PageRequest pageRequest) {
        long total = this.researchDepartmentDao.count(researchDepartment);
        return new PageImpl<>(this.researchDepartmentDao.queryAllByLimit(researchDepartment, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param researchDepartment 实例对象
     * @return 实例对象
     */
    @Override
    public ResearchDepartment insert(ResearchDepartment researchDepartment) {
        this.researchDepartmentDao.insert(researchDepartment);
        return researchDepartment;
    }

    /**
     * 修改数据
     *
     * @param researchDepartment 实例对象
     * @return 实例对象
     */
    @Override
    public ResearchDepartment update(ResearchDepartment researchDepartment) {
        this.researchDepartmentDao.update(researchDepartment);
        return this.queryById(researchDepartment.getResearchDepartmentId());
    }

    /**
     * 通过主键删除数据
     *
     * @param researchDepartmentId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer researchDepartmentId) {
        return this.researchDepartmentDao.deleteById(researchDepartmentId) > 0;
    }
}
